package dao

import (
	"github.com/go-xorm/xorm"

	"im/common"
	"im/errcode"
	"im/model"
	"im/service/orm"
)

type EsJobs struct {
	db *xorm.Engine
}

func NewEsJobs() EsJobs {
	return EsJobs{db: orm.GetDB()}
}

func (e EsJobs) List(docType string, limit int) ([]model.EsJobs, error) {
	var list []model.EsJobs
	err := e.db.Where("doc_type=?", docType).Limit(limit).Find(&list)
	if err != nil {
		return list, errcode.NewError(errcode.DaoFailed, err)
	}
	return list, nil
}
func (e EsJobs) Delete(docType string, docIds ...int64) error {
	_, err := e.db.In("doc_id", common.ToInterfaceSlice(docIds)...).Where("doc_type=?", docType).Delete(&model.EsJobs{})
	if err != nil {
		return errcode.NewError(errcode.DaoFailed, err)
	}
	return nil
}
